//
//  ChoicenessCell.m
//  PetTown
//
//  Created by lanou3g on 15/5/28.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "ChoicenessCell.h"

@implementation ChoicenessCell
- (void)setHomePage:(HomePage *)homePage{

    
    _home_disnameLable.text = homePage.disname;
    _home_contentLable.text = homePage.photo_des;
    if ([_home_contentLable.text isEqual: @""]) {
        _home_contentLable.text = @"{小主人好懒啊,什么都不写!}";
    }
    _home_contentLable.layer.cornerRadius = 5.0;
    _home_time.text = homePage.time;
    UIImage * imm = [UIImage imageNamed:@"place.jpg"];
    [_home_imageView sd_setImageWithURL:[NSURL URLWithString:homePage.photo] placeholderImage:imm];
    [_home_avatarView sd_setImageWithURL:[NSURL URLWithString:homePage.avatar] placeholderImage:imm];
    //计算图片高度
    _lableHeight = [[UIScreen mainScreen] bounds].size.width * [homePage.picheight floatValue] / [homePage.picwidth floatValue];
    //设置各种Frame
    _home_imageView.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, _lableHeight);
    _home_avatarView.frame = CGRectMake(20, _home_imageView.frame.size.height-20, 50, 50);
    _home_time.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width-100, _home_imageView.frame.size.height, 100, 50);
    _home_disnameLable.frame = CGRectMake(90, _home_imageView.frame.size.height, 100, 50);
    _home_contentLable.frame = CGRectMake(0, _home_imageView.frame.size.height+50, _home_imageView.frame.size.width, 50);
    _home_contentLable.textAlignment = NSTextAlignmentCenter;
    _home_contentLable.font = [UIFont systemFontOfSize:14];
    _pl_view.frame = CGRectMake(0, _home_imageView.frame.size.height+105, _home_imageView.frame.size.width, 75);
    _contentTF.frame = CGRectMake(15, _home_imageView.frame.size.height+185, _home_imageView.frame.size.width-75, 40);
    _publishButton.frame = CGRectMake(_home_imageView.frame.size.width-50, _home_imageView.frame.size.height+185, 40, 40);
    _mostPLLable.frame = CGRectMake(5, _home_imageView.frame.size.height+230, [[UIScreen mainScreen] bounds].size.width-10, 40);
    

}
-(void)setReviewer:(Reviewer *)reviewer{
    [_pl_imageView sd_setImageWithURL:[NSURL URLWithString:reviewer.avatar] placeholderImage:nil];
    _pl_time.text = reviewer.time;
    _pl_content.text = reviewer.content;
    _pl_name.text = [NSString stringWithFormat:@"{%@}的'%@'",reviewer.nickname,reviewer.disname];
    }

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self yy_setupSubviews];
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
- (void)yy_setupSubviews{
    //图片
    self.home_imageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_home_imageView];
    //头像
    self.home_avatarView = [[UIImageView alloc] init];
    [self.contentView addSubview:_home_avatarView];
    //发布时间
    self.home_time = [[UILabel alloc] init];
    [self.contentView addSubview:_home_time];
    _home_time.alpha = 0.6;
    //用户名
    self.home_disnameLable = [[UILabel alloc] init];
    [self.contentView addSubview:_home_disnameLable];
    _home_disnameLable.alpha = 0.6;
    //描述
    self.home_contentLable = [[UILabel alloc] init];
    _home_contentLable.backgroundColor = [UIColor whiteColor];
    _home_contentLable.layer.borderWidth = 0.5;
    _home_contentLable.alpha = 0.6;
    [self.contentView addSubview:_home_contentLable];
    //用户评论条
    self.pl_view = [[UIView alloc] init];
    _pl_view.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_pl_view];
    _pl_view.alpha = 0.6;
    //评论者头像
    self.pl_imageView = [[UIImageView alloc] init];
    _pl_imageView.frame = CGRectMake(10, 5, 40, 40);
    [_pl_view addSubview:_pl_imageView];
    //评论者昵称(nickname)及宠物昵称(disname)
    self.pl_name = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 200, 30)];
    [_pl_view addSubview:_pl_name];
  
    //发布时间
    self.pl_time = [[UILabel alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width-80, 0, 80, 30)];
    _pl_time.alpha = 0.6;
    [_pl_view addSubview:_pl_time];
    //评论内容
    self.pl_content = [[UILabel alloc] initWithFrame:CGRectMake(70, 30, [[UIScreen mainScreen] bounds].size.width-80, 50)];
    _pl_content.numberOfLines = 0;
    _pl_content.font = [UIFont systemFontOfSize:14];
    [_pl_view addSubview:_pl_content];

    

    
    
    //添加评论
    self.contentTF = [[UITextField alloc] init];
    _contentTF.placeholder = @"请输入评论内容...";
    _contentTF.textAlignment = NSTextAlignmentCenter;
    _contentTF.layer.borderWidth = 0.2;
    _contentTF.layer.cornerRadius = 10;
    _contentTF.delegate = self;
    _contentTF.alpha = 0.6;
    _contentTF.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_contentTF];
    //更多评论
    self.mostPLLable = [[UITextField alloc] init];
    _mostPLLable.backgroundColor = [UIColor whiteColor];
    _mostPLLable.text = @"更多评论";
    _mostPLLable.layer.borderWidth = 0.5;
    _mostPLLable.layer.cornerRadius = 20;
    _mostPLLable.enabled = NO;
    _mostPLLable.font = [UIFont systemFontOfSize:14];
    _mostPLLable.textAlignment = NSTextAlignmentCenter;
    _mostPLLable.alpha = 0.6;
    [self.contentView addSubview:_mostPLLable];
    
    //发表
    self.publishButton = [[UIButton alloc] init];
    [_publishButton setImage:[UIImage imageNamed:@"fabiaopinglun.png"] forState:UIControlStateNormal];
    _publishButton.alpha = 0.8;
    [_publishButton addTarget:self action:@selector(clickPublishBU:) forControlEvents:UIControlEventTouchDown];
    [self.contentView addSubview:_publishButton];
    
}
- (void)clickPublishBU:(UIButton *)publishButton{
    if ([_contentTF.text length] == 0) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"评论不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
        [alert show];
        }else{
            UIAlertView * alert1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的评论内容将在审核后显示" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert1 show];
    }
    
    _contentTF.text = nil;
    [_contentTF resignFirstResponder];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
@end
